/*
 * sso
 */
package com.opensso.domain.ctrl;

import com.alibaba.fastjson.JSON;
import com.opensso.core.exceptions.BaseException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.opensso.core.entity.BeanRet;
import com.opensso.core.entity.Page;
import com.opensso.core.tools.redis.RedisUtils;
import com.opensso.domain.entity.DomainLog;
import com.opensso.domain.service.DomainLogSV;

/**
 * 域名日志 控制器
 *
 * @author helixin
 */
@RestController
@RequestMapping("/domainLog")
@Slf4j
@Api(value = "域名日志控制器", description = "域名日志控制器")
public class DomainLogCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private DomainLogSV domainLogSV;

    /**
     * 查询DomainLog一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询DomainLog一个详情信息", notes = "查询DomainLog一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(java.lang.Long id) {
        if (id == null) {
            return null;
        }
        DomainLog domainLog = domainLogSV.load(id);
        log.info(JSON.toJSONString(domainLog));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, domainLog);
    }


    /**
     * 查询DomainLog信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询DomainLog信息集合", notes = "查询DomainLog信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "domainCode", value = "域名编码", paramType = "query"),
            @ApiImplicitParam(name = "account", value = "账户", paramType = "query"),
            @ApiImplicitParam(name = "clientIp", value = "客户端ip", paramType = "query"),
            @ApiImplicitParam(name = "serverIp", value = "服务器ip", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query"),
            @ApiImplicitParam(name = "requestUrl", value = "请求URL", paramType = "query"),
            @ApiImplicitParam(name = "domain", value = "域名", paramType = "query"),
            @ApiImplicitParam(name = "returnInfo", value = "返回信息 json 格式", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore DomainLog domainLog, Integer curPage, Integer pageSize) {
        Page<DomainLog> page = new Page<DomainLog>(pageSize, curPage);
        List<DomainLog> domainLogs = domainLogSV.list(domainLog, page.genRowStart(), page.getPageSize());
        int total = domainLogSV.count(domainLog);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, domainLogs);
    }


    /**
     * 查询DomainLog信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询DomainLog信息集合", notes = "查询DomainLog信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(java.lang.Long id, Integer curPage, Integer pageSize) {
        Page<DomainLog> page = new Page<DomainLog>(pageSize, curPage);
        List<DomainLog> domainLogs = domainLogSV.list(id, page.genRowStart(), page.getPageSize());
        int total = domainLogSV.count(id);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, domainLogs);
    }

    /**
     * 统计DomainLog信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计DomainLog信息数量根据主键", notes = " 统计DomainLog信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id) {
        return domainLogSV.count(id);
    }

    /**
     * 统计DomainLog信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计DomainLog信息数量", notes = "统计DomainLog信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "domainCode", value = "域名编码", paramType = "query"),
            @ApiImplicitParam(name = "account", value = "账户", paramType = "query"),
            @ApiImplicitParam(name = "clientIp", value = "客户端ip", paramType = "query"),
            @ApiImplicitParam(name = "serverIp", value = "服务器ip", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query"),
            @ApiImplicitParam(name = "requestUrl", value = "请求URL", paramType = "query"),
            @ApiImplicitParam(name = "domain", value = "域名", paramType = "query"),
            @ApiImplicitParam(name = "returnInfo", value = "返回信息 json 格式", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody DomainLog domainLog) {
        if (domainLog == null) {
            return domainLogSV.count(new HashMap());
        } else {
            return domainLogSV.count(domainLog);
        }
    }


    /**
     * 创建DomainLog
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建DomainLog", notes = "创建DomainLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "domainCodeBegin", value = "域名编码", paramType = "query"),
            @ApiImplicitParam(name = "domainCodeEnd", value = "域名编码", paramType = "query"),
            @ApiImplicitParam(name = "accountBegin", value = "账户", paramType = "query"),
            @ApiImplicitParam(name = "accountEnd", value = "账户", paramType = "query"),
            @ApiImplicitParam(name = "clientIpBegin", value = "客户端ip", paramType = "query"),
            @ApiImplicitParam(name = "clientIpEnd", value = "客户端ip", paramType = "query"),
            @ApiImplicitParam(name = "serverIpBegin", value = "服务器ip", paramType = "query"),
            @ApiImplicitParam(name = "serverIpEnd", value = "服务器ip", paramType = "query"),
            @ApiImplicitParam(name = "languageBegin", value = "语言", paramType = "query"),
            @ApiImplicitParam(name = "languageEnd", value = "语言", paramType = "query"),
            @ApiImplicitParam(name = "requestUrlBegin", value = "请求URL", paramType = "query"),
            @ApiImplicitParam(name = "requestUrlEnd", value = "请求URL", paramType = "query"),
            @ApiImplicitParam(name = "domainBegin", value = "域名", paramType = "query"),
            @ApiImplicitParam(name = "domainEnd", value = "域名", paramType = "query"),
            @ApiImplicitParam(name = "returnInfoBegin", value = "返回信息 json 格式", paramType = "query"),
            @ApiImplicitParam(name = "returnInfoEnd", value = "返回信息 json 格式", paramType = "query"),
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore DomainLog domainLog) {
        domainLogSV.save(domainLog);
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, domainLog);
    }


    /**
     * 修改DomainLog
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改DomainLog", notes = "修改DomainLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "domainCode", value = "域名编码", paramType = "query"),
            @ApiImplicitParam(name = "account", value = "账户", paramType = "query"),
            @ApiImplicitParam(name = "clientIp", value = "客户端ip", paramType = "query"),
            @ApiImplicitParam(name = "serverIp", value = "服务器ip", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query"),
            @ApiImplicitParam(name = "requestUrl", value = "请求URL", paramType = "query"),
            @ApiImplicitParam(name = "domain", value = "域名", paramType = "query"),
            @ApiImplicitParam(name = "returnInfo", value = "返回信息 json 格式", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore DomainLog domainLog) {
        domainLogSV.modify(domainLog);
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, domainLog);
    }

    /**
     * 删除DomainLog
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除DomainLog", notes = "删除DomainLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id) {
        domainLogSV.delete(id);
        return BeanRet.create(true, "删除DomainLog成功");
    }

}
